<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <script src="json-util.js"></script>
    <script src="str-util.js"></script>
    <script src="md5.js"></script>
    <script src="date-util.js"></script>
    <script src="mapping-util.js"></script>
</head>
<body>

</body>
<script type="text/javascript">

    var mapping = [{
        id: "主键",
        name: {
            mappingKey: "姓名",
            mappingFunc: function (value) {
                if (value === "隔壁老王") {
                    return "被内部函数处理过" + value;
                }
            }
        },
        age: {
            mappingKey: "年龄",
            require: true,
            mappingFunc: function (value) {
                var reg1 = /(\d+)岁(\d+)月/;
                if (reg1.test(value)) {
                    var matchRes = value.match(reg1);
                    return (parseFloat(matchRes[1]) + parseFloat(matchRes[2]) / 12).toFixed(1);
                }

                var reg2 = /(\d+)岁/;
                if (reg2.test(value)) {
                    return value.replace('岁', '');
                }

                var reg3 = /(\d+)月/
                if (reg3.test(value)) {
                    var months = value.replace('月', '');
                    return (months / 12).toFixed(1);
                }

                return value;
            }
        }
    }];

    var allData = {
        "主键": "s101",
        "姓名": "隔壁老王",
        "年龄": "1岁6月"    // 该字段可以接收三种形式: 1岁、1岁3月、6月
    };

    console.log(MAPPING_UTIL.mappingHandle(mapping, allData));

</script>
</html>